<template>
	<view class="add-view">
		<view class="top-bar"><uni-navbar :fixed="true" :back="true" color="#fff" :title="title"></uni-navbar></view>

		<view class="form-box">
			<u-form :model="form" ref="uForm">
				<u-form-item class="form-item" required label="审核结果">
					<u-radio-group v-model="approve" @change="approveGroupChange" :key="approve">
						<u-radio v-for="(item, index) in approveList" :key="index" :name="item.name" :disabled="item.disabled">{{ item.label }}</u-radio>
					</u-radio-group>
				</u-form-item>

				<u-form-item class="form-item" label="审核意见" v-if="form.approveFlag == 2">
					<!-- block -->
					<u-input v-model="form.approveIdea" type="textarea" placeholder="请输入审核意见" :clearable="false" :height="160" :maxlength="-1" />
				</u-form-item>
			</u-form>
		</view>

		<view class="fiexd-btm"><u-button class="form-btn" type="error" @click="confirm">提交</u-button></view>

		<view v-if="false && qjList"></view>
	</view>
</template>

<script>
import { mapState } from 'vuex';
export default {
	data() {
		return {
			id: '',
			title: '履职审核',
			navItem: 1,

			approve: '1',
			approveList: [
				{
					name: '1',
					label: '通过'
				},
				{
					name: '2',
					label: '不通过'
				}
			],

			performDate: '',
			performEndDate: '',

			form: {
				performId: '',
				approveFlag: '1',
				approveIdea: ''
			},
			rules: {
				title: [
					{
						required: true,
						message: '请输入标题',
						trigger: 'change'
					}
				]
			}
		};
	},
	onLoad(option) {
		this.loadLogin();
		this.id = option.id;
	},
	onReady() {
		this.$refs.uForm.setRules(this.rules);
	},
	onUnload() {
		this.$store.commit('filePush', []);
	},
	computed: {
		...mapState(['userInfo', 'fileList'])
	},
	methods: {
		loadLogin() {
			if (this.userInfo.Authorization) {
				this.clientCode = this.userInfo.sysUser.clientCode;
				this.userId = this.userInfo.sysUser.id;
			} else {
				this.$logout();
			}
		},
		approveGroupChange(e) {
			this.form.approveFlag = e;
		},
		confirm() {
			let data = {};
			if (this.id) {
				this.form.performId = this.id;
			}

			if (this.form.approveFlag == '2' && this.form.approveIdea == '') {
				this.$msg('请输入审核意见');
				return false;
			}

			this.form.clientCode = this.clientCode;
			this.form.currentUserId = this.userId;
			data = {
				...this.form
			};
			this.$request('/perform/approve', data, {
				load: true
			}).then((res) => {
				this.$msg(res.msg);
				setTimeout(() => {
					let pre = this.$prePage();
					if (pre && pre.loadData) {
						pre.loadData('refresh');
					}
					uni.navigateBack();
				}, 500);
			});
		}
	}
};
</script>

<style lang="scss">
.add-view {
	background-color: #fff;
}

.form-box {
	border-top: 20rpx solid $u-border-color;

	.form-item {
		@include mp-flex;
		border-bottom: 20rpx solid $u-border-color;
	}
}

.fiexd-btm {
	position: static;
	padding: 30rpx;
}
</style>
